package com.css.bjdt_report.report.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.nutz.dao.sql.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.css.bjdt_report.report.entity.RptGroupAndReportTreeEntity;
import com.css.bjdt_report.report.service.ReportManageService;
import com.css.bjdt_report.util.PropertyFilter;

@Controller
@RequestMapping(value = "/reportManageController")
public class ReportManageController {

	@Autowired
	private ReportManageService reportManageService;

	@RequestMapping("/reportTreeList")
	public String reportTreeList() {
		return "/report-manage/report-manage-list-all";
	}

	@ResponseBody
	@RequestMapping(value = "/queryALLGroupAndReportByAnnual/{annualId}", method = RequestMethod.POST)
	public List<RptGroupAndReportTreeEntity> queryALLGroupAndReportByAnnual(@PathVariable String annualId) {
		List<RptGroupAndReportTreeEntity> rptGroupAndReportTreeEntityList = new ArrayList<RptGroupAndReportTreeEntity>();
		rptGroupAndReportTreeEntityList = reportManageService.queryReportByAnnualId(annualId);
		return rptGroupAndReportTreeEntityList;
	}

	//查询报表模板，并生成LIGERUI格式的json
	@ResponseBody
	@RequestMapping(value = "/groupTableData/{annualId}", method = RequestMethod.POST)
	public Map groupTableData(@PathVariable String annualId, HttpServletRequest request,
			@RequestParam(value = "pageNum") int pageNum, @RequestParam(value = "pageSize") int pageSize,
			@RequestParam(value = "sortname") String sortname, @RequestParam(value = "sortorder") String sortorder) {
		Criteria cnd = PropertyFilter.cri(request);

		cnd.where().and("ANNUALID", "=", annualId);

		cnd.getOrderBy().desc("ORDERID");

		return reportManageService.queryPage(cnd, pageNum, pageSize);
	}

	//查询报表模板，并生成LIGERUI格式的json
	@ResponseBody
	@RequestMapping(value = "/templateTableData/{groupId}", method = RequestMethod.POST)
	public Map tableData(@PathVariable String groupId, HttpServletRequest request,
			@RequestParam(value = "pageNum") int pageNum, @RequestParam(value = "pageSize") int pageSize,
			@RequestParam(value = "sortname") String sortname, @RequestParam(value = "sortorder") String sortorder) {
		Criteria cnd = PropertyFilter.cri(request);

		cnd.where().and("GROUPID", "=", groupId);

		cnd.getOrderBy().asc("TEMPLATEORDERID");

		return reportManageService.queryTemplatePage(cnd, pageNum, pageSize);
	}

}
